<?php
namespace app\common\service\Users;

use app\common\entity\User;


class Cache
{
    const CACHE_NAME = 'members_all';

    const CACHE_TTS = 300;

    public function getAllUsers()
    {
        /*$users = User::field('id,pid')->select()->toArray();
        return $users;*/
        $users = \think\facade\Cache::remember(self::CACHE_NAME, function () {
            //获取全部用户
            $users = User::field('id,pid')->select()->toArray();
            return $users;

        });

        return $users;

    }

    public function addUsers($data)
    {
        //获取全部收据
        $users = $this->getAllUsers();
        array_push($users,$data);

        \think\facade\Cache::set(self::CACHE_NAME,$users);

    }

    public function delCache()
    {
        \think\facade\Cache::rm(self::CACHE_NAME);
    }
}

